function [sys,x0,str,ts] = d_track(t,x,u,flag)

switch flag,
case 0,
    [sys,x0,str,ts]=mdlInitializeSizes;
case 3,
    sys=mdlOutputs(t,x,u);
case {1,2,4,9}
    sys=[];
otherwise
    error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 4;
sizes.NumInputs      = 0;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0  = [];
str = [];
ts  = [0 0];
function sys=mdlOutputs(t,x,u)

xd=zeros(4,1);
vd=zeros(4,1);
ad=zeros(4,1);

A=zeros(4,1);
A(1)=40*pi;
A(2)=60*pi;
A(3)=100*pi;
A(4)=5*pi;


T=8*pi;

if t<=T/2
    for i=1:4
          xd(i)=(-A(i)/2/pi)*sin(4*pi*t/T)+2*A(i)*t/T;
          vd(i)=(-A(i)*2/T)*cos(4*pi*t/T)+2*A(i)/T;
          ad(i)=(A(i)*8*pi/T/T)*sin(4*pi*t/T);
    end
end

if t>T/2
    for i=1:4
          xd(i)=A(i);
          vd(i)=0;
          ad(i)=0;
    end
end

for j=1:4
    sys(j)=xd(j);
end






